package com.zj.common;

import com.zj.exception.PermissionException;
import com.zj.exception.RequestLimitException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import com.zj.exception.LoginException;

//mvc的异常处理器
//@ControllerAdvice
@RestControllerAdvice
public class ProjectExceptionAdvice {
    @ExceptionHandler(Exception.class)
    public Result doException(Exception e){
        //记录日志
        //通知运维
        //通知开发
        e.printStackTrace();
        return Result.error("服务器异常,请稍后重试！");
    }
    //自定义登录异常
    @ExceptionHandler(LoginException.class)
    public Result LoginException(LoginException e){
        return Result.error(e.getMsg());
    }
    //自定义权限异常
    @ExceptionHandler(PermissionException.class)
    public Result PermissionException(PermissionException e){
        return Result.error(e.getMsg());
    }
    //自定义登录异常
    @ExceptionHandler(RequestLimitException.class)
    public Result RequestLimitException(RequestLimitException e){
        return Result.error(e.getMsg());
    }
}
